<?php
require_once("include/auth.php");
require_once("include/db.php");

if (!isset($_GET['token'])) {
    die('Token not specified.');
}
$token = $_GET['token'];
$device = get_device($token);
$location = query_device_location($device['ID']);

$title = "Location Map (Device " . $device['Device_Name'] . ")";
require('include/header.php');
?>

<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=AmCDLiYiEmBn2vpryV3C5U4L"></script>

<!-- Begin page content -->
<div class="container">
    <div class="page-header">
        <h1><?php echo $title; ?></h1>
    </div>
    <div class="page-content">
        <div id="allmap"></div>
    </div>
</div>

<script type="text/javascript">
var points = [];
var time = [];
<?php
while ($row = mysql_fetch_assoc($location)) {
    $lng = $row['Longitude'];
    $lat = $row['Latitude'];
    echo "points.push(new BMap.Point($lng, $lat));\n";
    echo "time.push('".$row['Created_Time']."');\n";
}
?>
setTimeout(function(){location.reload();}, 30 * 1000);    
</script>
<script type="text/javascript" src="js/map.js"></script>

<?php require('include/footer.php'); ?>
